package com.neusoft.zqygbc.neusoft_wenda.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.neusoft.zqygbc.neusoft_wenda.R;
import com.neusoft.zqygbc.neusoft_wenda.activity.QuestionContentActivity;
import com.neusoft.zqygbc.neusoft_wenda.base.RecyclerViewAdapter;
import com.neusoft.zqygbc.neusoft_wenda.javeBean.QuestionEntity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by Shinelon on 2017/5/21.
 */

public class CollectAdapter extends RecyclerViewAdapter<CollectAdapter.ViewHolder> {

    public CollectAdapter(Context context, List data, int layoutResource) {
        super(context, data, layoutResource);
    }

    @Override
    public void onBindViewHolder(final CollectAdapter.ViewHolder holder, final int position) {
        final QuestionEntity entity =  (QuestionEntity)data.get(position);
    //   Picasso.with(context).load("http://115.159.93.244/wenda/Public/userphoto/" + entity.getPhotos()).into(holder.usercollect_userphoto);
        holder.mycollect_username.setText(entity.getUsername());
        switch (entity.getTid()) {

            case "1":
                holder.mycollect_type.setText("Android");
                break;

            case "2":
                holder.mycollect_type.setText("PHP");
                break;

            case "3":
                holder.mycollect_type.setText("Web");
                break;

            case "4":
                holder.mycollect_type.setText("iOS");
                break;

            default:
                break;
        }
        holder.mycollect_description.setText(entity.getDescription());
        holder.usercollect.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, QuestionContentActivity.class);
                intent.putExtra("qid", entity.getQid());
                intent.putExtra("question_uid", entity.getUid());
                context.startActivity(intent);
            }
        });

    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView mycollect_username,mycollect_type,mycollect_description;
        LinearLayout usercollect;
        ImageView usercollect_userphoto;


        public ViewHolder(View itemView) {
            super(itemView);
            usercollect_userphoto = (ImageView) itemView.findViewById(R.id.usercollect_userphoto);
            mycollect_username = (TextView) itemView.findViewById(R.id.mycollect_username);
            mycollect_type = (TextView) itemView.findViewById(R.id.mycollect_type);
            mycollect_description = (TextView) itemView.findViewById(R.id.mycollect_description);
            usercollect = (LinearLayout) itemView.findViewById(R.id.usercollect);

        }
    }

}
